/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						 external_string.h

	$Header: /game/external_string.h $

	$NoKeywords: $

 ************************************************************************/

#if !defined(EXTERNAL_STRING_H_INCLUDED)
#define EXTERNAL_STRING_H_INCLUDED

#pragma warning( disable: 4786 )

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <string>

#if !defined( NDEBUG )
#include <list>
#include "shared_ptr.h"
#endif // !defined( NDEBUG )

class t_string_table;
// --------------------------------------------------------------------------
// string which is loaded from from a string table on first use.
// --------------------------------------------------------------------------
class t_external_string
{
public:
	// Static member functions
	static void	add_table( t_string_table const & new_string_table );
	static int	load_all(); // Does nothing in release build

	// Constructor/Destructor
	t_external_string( std::string const & key );
	~t_external_string();

	// Member functions
	char const *		c_str() const;
	std::string const &	get() const;

	// Operator
	operator std::string const & () const;

private:
	// Data members
	std::string     m_string;
	bool            m_loaded;
	bool			m_found;

#if !defined( NDEBUG )
	// Types
	typedef std::list< t_external_string * >	t_instance_list;
	typedef t_shared_ptr< t_instance_list > t_instance_list_ptr;

	static t_instance_list_ptr get_list();

	t_instance_list_ptr m_list;
#endif // !defined( NDEBUG )

	// Member functions
	void load_string();
};

// -----------------------------------------------------------
// inlines for t_external_string
// -----------------------------------------------------------

#if defined( NDEBUG )

inline int t_external_string::load_all()
{
	return 0;
}

inline t_external_string::~t_external_string()
{
}

#endif // defined( NDEBUG )

inline std::string const & t_external_string::get() const
{
	if ( !m_loaded )
		const_cast< t_external_string * >( this )->load_string();
	return m_string;
}

inline char const * t_external_string::c_str() const
{
	return get().c_str();
}

inline t_external_string::operator std::string const & () const
{
	return get();
}

#endif // EXTERNAL_STRING_H_INCLUDED
